#-*-coding:utf8;-*-
#qpy:3
#qpy:console

import smtplib
from email.mime.text import MIMEText
from email.header import Header

def Sendtomail(mailmessage,phonenum):
	
	# 第三方 SMTP 服务
#新浪邮箱要求sender from mailuser一致，否则无法发送
	mail_host="smtp.sina.com"  #设置服务器
	mail_user="username"    #用户名
	mail_pass="yourpassword"   #口令 


	sender = 'youemail@example.com'
	receivers = ['youreceive@adderss.com']  # 接收邮件，可设置为你的QQ邮箱或者其他邮箱

	message = MIMEText(str(mailmessage), 'plain', 'utf-8')
	message['From'] = Header("chenphone001@sina.com", 'ascii')
	message['To'] =  Header("you", 'utf-8')

	subject = str(phonenum)
	message['Subject'] = Header(subject, 'utf-8')
#	print(mail_pass)

try:
		smtpObj = smtplib.SMTP_SSL(mail_host, 465) 
		smtpObj.ehlo()
		smtpObj.login(mail_user,mail_pass)  
		smtpObj.sendmail(str(sender), receivers, message.as_string())
		print("邮件发送成功")
		
		smtpObj.close()
		return 1
except smtplib.SMTPException:
   	print("Error: 无法发送邮件")
      raise
		return 0
#Sendtomail("测试",10086)